<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <script src="../js/vue.js"></script>
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>



    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>工作台<small>菜单管理</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>工作台</el-breadcrumb-item>
                    <el-breadcrumb-item>菜单管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="名称" v-model="queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="small" border="true" current-row-key="id" :data="dataList" style="width:100%" stripe highlight-current-row >
                        <el-table-column type="expand">
                            <template slot-scope="props">
                                <el-table size="small" :data="props.row.children" current-row-key="id" :show-header="false" style="width:100%">
                                    <el-table-column type="index" align="center" width="48%"></el-table-column>
                                    <el-table-column prop="name" align="center" width="160%"></el-table-column>
                                    <el-table-column prop="level" align="center" width="160%">
                                        <template slot-scope="scope">
                                            <span>{{ scope.row.level == '0' ? '操作' : scope.row.level == '1' ? '目录' : '页面'}}</span>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="icon" align="center" width="160%"></el-table-column>
                                    <el-table-column prop="linkUrl" align="center" width="163%"></el-table-column>
                                    <el-table-column prop="path" align="center" width="160%"></el-table-column>
                                    <el-table-column prop="description" align="center" width="160%"></el-table-column>
                                    <el-table-column label="操作" align="center" width="160%">
                                        <template slot-scope="scope">
                                            <el-button type="primary" size="mini" @click="handleUpdate(scope.row)" >编辑</el-button>
                                            <el-button type="danger" size="mini" @click="handleDelete(scope.row)" >删除</el-button>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </template>
                        </el-table-column>
                        <el-table-column type="index" label="序号" align="center"></el-table-column>
                        <el-table-column prop="name" label="名称" align="center"></el-table-column>
                        <el-table-column prop="level" label="类型" align="center">
                            <template slot-scope="scope">
                                <span>{{ scope.row.level == '0' ? '操作' : scope.row.level == '1' ? '目录' : '页面'}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="icon" label="图标" align="center"></el-table-column>
                        <el-table-column prop="linkUrl" label="页面地址" align="center"></el-table-column>
                        <el-table-column prop="path" label="层次" align="center"></el-table-column>
                        <el-table-column prop="description" label="描述" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                                <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                        <el-table-column  label="" align="center" width="50%"></el-table-column>
                    </el-table>

                    <div class="add-form">
                        <el-dialog title="新增" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="新增目录" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="目录名称">
                                                        <el-input v-model="menuLine.name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="目录图标">
                                                        <el-input v-model="menuLine.icon"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-form-item label="目录序号">
                                                    <el-input v-model="menuLine.priority"/>
                                                </el-form-item>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="目录说明">
                                                        <el-input v-model="menuLine.description" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="新增页面" name="second" >
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="页面名称">
                                                        <el-input v-model="name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="页面图标">
                                                        <el-input v-model="icon"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="页面地址">
                                                        <el-input v-model="linkUrl"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="父目录">
                                                        <el-select v-model="value8" filterable placeholder="请选择">
                                                            <el-option
                                                                    v-for="item in options"
                                                                    :key="item.id"
                                                                    :label="item.value"
                                                                    :value="item.id">
                                                            </el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="页面说明">
                                                        <el-input v-model="description" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                    <!-- 编辑标签弹层 -->
                    <div class="edit-form">
                        <el-dialog title="编辑" :visible.sync="dialogFormVisible4Edit">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="编辑目录" name="first" :disabled="disabledJudge.first=='1'">
                                        <el-form label-position="right" label-width="100px" >
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="目录名称">
                                                        <el-input v-model="menuLine.name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="目录图标">
                                                        <el-input v-model="menuLine.icon"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-form-item label="目录序号">
                                                    <el-input v-model="menuLine.priority"/>
                                                </el-form-item>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="目录说明">
                                                        <el-input v-model="menuLine.description" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="编辑页面" name="second" :disabled="disabledJudge.second=='1'">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="页面名称">
                                                        <el-input v-model="menuLine.name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="页面图标">
                                                        <el-input v-model="menuLine.icon"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="页面地址">
                                                        <el-input v-model="menuLine.linkUrl"/>
                                                    </el-form-item>
                                                </el-col>
<!--                                                <el-col :span="12">-->
<!--                                                    <el-form-item label="页面层次">-->
<!--                                                        <el-input v-model="page.path"/>-->
<!--                                                    </el-form-item>-->
<!--                                                </el-col>-->
                                                <el-col :span="12">
                                                    <el-form-item label="父目录">
                                                        <el-select v-model="value8" filterable placeholder="请选择">
                                                            <el-option
                                                                    v-for="item in options"
                                                                    :key="item.id"
                                                                    :label="item.value"
                                                                    :value="item.id">
                                                            </el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="页面说明">
                                                        <el-input v-model="menuLine.description" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                                <el-button type="primary" @click="handleEdit()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>

    </body>



    <script>

        

        var vue = new Vue({
            el: '#app',
            data:{
                value8: '',
                options: [{
                    id: '选项1',
                    value: '黄金糕'
                }],

                disabledJudge:{
                    first:0,
                    second:0
                },
                activeName:'first',
                dataList: [],
                menuLine: {
                    name:"kkkkk",
                    priority:"10"
                },

                queryString:null,
                checkitemIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
                dialogFormVisible: false,//控制添加窗口显示/隐藏
                dialogFormVisible4Edit:false//控制编辑窗口显示/隐藏
            },
            // created() {
            //     this.findPage();
            // },
            methods: {
                // findPage() {
                //     var QueryPageBean = {
                //         queryString:this.queryString
                //     };
                //     axios.post("/menu/findByPage.do",QueryPageBean).then(res=>{
                //         this.$message({
                //             message: res.data.message,
                //             type: res.data.flag ? 'success':'error'
                //         });
                //         if(res.data.flag){
                //             this.dataList = res.data.data;
                //         }
                //     })
                // },

                // 弹出添加窗口
                handleCreate() {
                    //清空表单数据 以及 默认选中第一个选项卡
                    this.resetForm();
                    this.dialogFormVisible = true;
                    axios.get("/menu/getParent.do").then(res=>{

                        if(res.data.flag){
                            this.options = res.data.data;
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                        }
                        else {
                            this.$message.error(res.data.message);
                        }
                    })
                },

                //添加
                handleAdd() {

                    // this.menuLine.parentMenuId = this.value8;
                    axios.post("/menu/addMenu.do",this.menuLine).then(res=>{
                        this.dialogFormVisible = false;
                        this.$message({
                            message: res.data.message,
                            type: res.data.flag ? 'success':'error'
                        });
                        this.findPage();
                    })
                },

                // // 重置表单
                resetForm() {
                    this.formData = {};
                    this.checkitemIds = [];
                    this.activeName ='first';
                    this.menuLine ={};
                    this.options =[];
                    this.disabledJudge.second=0;
                    this.disabledJudge.first=0;

                }
                //
                // //切换页码
                // handleCurrentChange(currentPage) {
                //     this.pagination.currentPage = currentPage;
                //     this.findPage();
                // }
            }
        })
    </script>
</html>
